version: '3.9'
services:
  spring:
    build:
      context: ..
      dockerfile: Dockerfile
    ports:
      - "8080:8080"
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_URL: ${POSTGRES_URL}
      REDIS_HOST: ${REDIS_HOST}
      REDIS_PORT: ${REDIS_PORT}
      REDIS_PASSWORD: ${REDIS_PASSWORD}
      MINIO_ROOT_USER: ${MINIO_ROOT_USER}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
      MINIO_CLIENT_ENDPOINT: ${MINIO_CLIENT_ENDPOINT}
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      minio:
        condition: service_healthy
    env_file:
      - .env

  postgres:
    image: postgres
    container_name: postgres
    restart: unless-stopped
    environment:
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - PGDATA=${POSTGRES_PGDATA}
    volumes:
      - /var/lib/postgresql/data:/var/lib/postgresql/data
    ports:
          - "5432:5432"
    env_file:
      - .env
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready" ]
      interval: 5s
      timeout: 5s
      retries: 5

  redis:
    image: redis
    container_name: redis
    ports:
      - "6379:6379"
    volumes:
    - ~/data/redis:/var/lib/redis
    - ~/data/redis/config:/usr/local/etc/redis/redis.conf
    environment:
      REDIS_PASSWORD: ${REDIS_PASSWORD}
    env_file:
      - .env
    healthcheck:
      test: [ "CMD-SHELL", "redis-cli ping | grep PONG" ]
      interval: 5s
      timeout: 5s
      retries: 5

  minio:
    image: bitnami/minio
    container_name: minio
    restart: unless-stopped
    ports:
      - '9000:9000'
      - '9001:9001'
    environment:
      - MINIO_ROOT_USER=${MINIO_ROOT_USER}
      - MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASSWORD}
    volumes:
      - /var/lib/minio/data:/var/lib/minio/data
    env_file:
      - .env
    healthcheck:
      test: [ "CMD", "curl", "-f", "http://127.0.0.1:9000/minio/health/live" ]
      interval: 5s
      timeout: 5s
      retries: 5